import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/2/16 14:38
 * @description 原地修改，将空间复杂度为O(1)
 */
public class FormalSolution {
    public static void main(String[] args) {
        FormalSolution solution = new FormalSolution();
        int[] nums = {4,3,2,7,8,2,3,1};
        solution.findDisappearedNumbers(nums);
    }
    public List<Integer> findDisappearedNumbers(int[] nums) {
        int n = nums.length;
        for (int num: nums) {
            // 因为 num可能增加 了n，让他取模还原值
            int x = (num - 1) % n;
            // 让 x-1处增加 n
            nums[x] += n;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n ; i++) {
            if (nums[i] <= n) {
                // 若当前未大于n，说明没有遇到过 i + 1
                list.add(i + 1);
            }
        }
        return list;
    }
}
